<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"/>
	<title>缓冲动画小栗子</title>
</head>
<style type="text/css">
	#box{
		height: 100px;
		width: 200px;
		position: relative;
		left: 0px;
		background-color: blue;
	}
</style>
<script type="text/javascript">
	window.onload=function(){
		var oBox=document.getElementById('box');
		console.log(oBox);
		oBox.onmouseover=function(){
			startMove(600);
		}
		oBox.onmouseout=function(){
			startMove(0);
		}
	}
	var timer=null;
	function startMove(iTarget){	
	var oBox=document.getElementById('box');
		timer=setInterval(function(){
			var speed=(iTarget-oBox.offsetLeft)/20;			
			speed=speed>0?Math.ceil(speed):Math.floor(speed);
			console.log(speed);
			if(oBox.offsetLeft==iTarget){
				clearInterval(timer);
			}else{
				oBox.style.left=oBox.offsetLeft+speed+'px';
			}
			console.log(oBox.offsetLeft);
		},100);
	}
</script>
<body>
 	<div id="box">火车</div>
</body>
</html>